<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改用户')" />
	<th:block th:include="include :: select2-css" />
</head>
<body>
<div class="main-content">
	<form class="form-horizontal" id="form-user-edit" th:object="${info}">
		<input name="userId"  type="hidden"  th:field="*{userId}" />
		<h4 class="form-header h4">基本信息</h4>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label"><span style="color: red; ">*</span>登录账号：</label>
					<div class="col-sm-8">
						<input class="form-control" type="text" readonly="true" th:field="*{userName}"/>
					</div>
				</div>
			</div>
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label"><span style="color: red; ">*</span>用户名称：</label>
					<div class="col-sm-8">
						<input name="trueName" placeholder="请输入用户真实姓名" class="form-control" type="text" maxlength="30" th:field="*{trueName}" required>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label"><span style="color: red; ">*</span>手机号码：</label>
					<div class="col-sm-8">
						<input name="phoneNumber" placeholder="请输入手机号码" class="form-control" type="text" maxlength="11" th:field="*{phoneNumber}" required>
					</div>
				</div>
			</div>
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label"><span style="color: red; ">*</span>邮箱：</label>
					<div class="col-sm-8">
						<input name="email" class="form-control email" type="text" maxlength="50" placeholder="请输入邮箱" th:field="*{email}" required>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label">用户性别：</label>
					<div class="col-sm-8">
						<select name="sex" class="form-control m-b" >
							<option value="0" th:selected= "${info?.sex == '0'}" >男</option>
							<option value="1" th:selected= "${info?.sex == '1'}" >女</option>
						</select>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-12">
				<div class="form-group">
					<label class="col-xs-2 control-label">角色：</label>
					<div class="col-xs-10">
						<label th:each="role:${roles}" class="check-box">
							<input name="role" type="checkbox" th:value="${role.roleId}" th:text="${role.roleName}" th:checked="${role.flag}" th:disabled="${role.status == '1'}">
						</label>
					</div>
				</div>
			</div>
		</div>
	</form>
</div>
<div class="row">
	<div class="col-sm-offset-5 col-sm-10">
		<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
		<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
	</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script type="text/javascript">
	var prefix ="/sys/user";

	$("#form-user-edit").validate({
		onkeyup: false,
		rules:{
			email:{
				email:true,
				remote: {
					url: prefix + "/checkEmailUnique",
					type: "post",
					dataType: "json",
					data: {
						"userId": function() {
							return $("#userId").val();
						},
						"email": function() {
							return $.common.trim($("#email").val());
						}
					},
					dataFilter: function (data, type) {
						return $.validate.unique(data);
					}
				}
			},
			phoneNumber:{
				isPhone:true,
				remote: {
					url: prefix + "/checkPhoneUnique",
					type: "post",
					dataType: "json",
					data: {
						"userId": function() {
							return $("#userId").val();
						},
						"phoneNumber": function() {
							return $.common.trim($("#phoneNumber").val());
						}
					},
					dataFilter: function (data, type) {
						return $.validate.unique(data);
					}
				}
			},
		},
		messages: {
			"email": {
				remote: "Email已经存在"
			},
			"phonenumber":{
				remote: "手机号码已经存在"
			}
		},
		focusCleanup: true
	});

	function submitHandler() {
		if ($.validate.form()) {
			var data = $("#form-user-edit").serializeArray();
			var roleIds = $.form.selectCheckeds("role");
			data.push({"name": "roleIds", "value": roleIds});
			$.operate.saveTab(prefix + "/saveOrUpdate", data);
		}
	}
</script>
</body>
</html>